/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.GerenciarTREF;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JOptionPane;
import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;

/**
 * FramePattern
 *
 * Versao 1.0
 *
 * Data Criação 13/03/2014
 *
 * @author Igor
 */
public abstract class FramePattern extends javax.swing.JInternalFrame {

    //Atributos
    protected boolean validarSair;

    //Construtores
    public FramePattern() {
        this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        this.validarSair = false;

        this.addInternalFrameListener(
                new InternalFrameAdapter() {
                    @Override
                    public void internalFrameClosing(InternalFrameEvent e) {
                        fecharAplicacao();
                    }
                }
        );
    }

    protected void fecharAplicacao() {
        if (validarSair) {
            if (JOptionPane.showConfirmDialog(this, "Deseja realmente fechar a tela?\nTodos dados não salvos serão perdidos.", "Atenção", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) {
                return;
            }
        }
        dispose();
    }
}
